package org.kleathome.dcpu16;

import org.kleathome.dcpu16.emulator.Emulator;

public class DCPU16Register extends DCPU16Value
{
	protected Emulator.Registers _register;

	public DCPU16Register(char value)
	{
		if (value >= 0x00 && value <= 0x07)
			_register = Emulator.Registers.values()[value];
		else if (value == 0x1B)
			_register = Emulator.Registers.SP;
		else if (value == 0x1C)
			_register = Emulator.Registers.PC;
		else if (value == 0x1D)
			_register = Emulator.Registers.O;
	}
	
	public void setValue(char val)
	{
		Emulator.setRegister(_register, val);
	}
	
	public char getValue()
	{
		return Emulator.getRegister(_register);
	}
	
	public String toString()
	{
		return "Register " + _register;
	}

	@Override
	public int getCycleCost()
	{
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getInstructionWords()
	{
		return 0;
	}
	
	@Override
	public void updateJumpAddresses()
	{
	}

	@Override
	public int getOpCode()
	{
		if (_register == Emulator.Registers.O)
			return 0x1D;
		if (_register == Emulator.Registers.PC)
			return 0x1C;
		if (_register == Emulator.Registers.SP)
			return 0x1B;
		return _register.ordinal();
	}
	@Override
	public char getDataCode()
	{
		return 0;
	}
}
